package com.example.service.impl;

import com.example.dao.AssessorDao;
import com.example.entity.Assessor;
import com.example.service.AssessorService;
import com.example.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * 学生对象服务层接口实现类
 * @author 李平
 * @Date 2022-5-1
 */
@Service
public class AssessorServiceImpl implements AssessorService {

    @Autowired
    private AssessorDao assessorDao;

    /**
     * 用户登录业务
     * @param phone
     * @param password
     * @return Student
     */
    @Override
    public Assessor getAssessorByPAndP(String phone, String password) {
        return assessorDao.getAssessorByPAndP(phone, MD5Util.md5(password));
    }

    /**
     * 通过电话号码查询学生信息业务
     * @param phone
     * @return Student
     */
    @Override
    public Assessor getAssessorByPhone(String phone) {
        return assessorDao.getAssessorByPhone(phone);
    }

    /**
     * 用户注册业务
     * @param assessor
     * @return Boolean
     */
    @Override
    public Boolean addAssessor(Assessor assessor) {
        // 通过电话号码查询
        Assessor stu = assessorDao.getAssessorByPhone(assessor.getPhone());
        if (stu == null) {
            // 当前电话号码未存储于数据库中
            assessor.setId(UUID.randomUUID().toString());
            assessor.setPassword(MD5Util.md5(assessor.getPassword()));
            return assessorDao.addAssessor(assessor);
        }else {
            // 当前电话号码已存储于数据库中
            return false;
        }
    }



}
